<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的图床 - 增强版</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            padding: 20px;
            background-color: #f5f5f5;
            font-family: "Microsoft YaHei", sans-serif;
        }
        .title {
            text-align: center;
            margin-bottom: 30px;
            color: #2c3e50;
        }
        .image-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 25px;
            max-width: 1400px;
            margin: 0 auto;
        }
        .image-item {
            background: white;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 3px 6px rgba(0,0,0,0.12);
            transition: all 0.3s ease;
        }
        .image-item:hover {
            transform: translateY(-6px);
            box-shadow: 0 8px 16px rgba(0,0,0,0.15);
        }
        .image-item img {
            width: 100%;
            height: 220px;
            object-fit: cover;
            cursor: pointer;
            border-bottom: 1px solid #eee;
        }
        .image-info {
            padding: 15px;
        }
        .image-name {
            font-size: 14px;
            color: #555;
            margin-bottom: 10px;
            word-break: break-all;
        }
        .copy-btn {
            width: 100%;
            padding: 8px 0;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: background 0.2s;
        }
        .copy-btn:hover {
            background-color: #2980b9;
        }
        .copy-btn.copied {
            background-color: #27ae60;
        }

        /* 预览弹窗 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.85);
            z-index: 100;
            align-items: center;
            justify-content: center;
        }
        .modal-content {
            position: relative;
            text-align: center;
        }
        .modal img {
            max-width: 90%;
            max-height: 85%;
            object-fit: contain;
            border: 5px solid white;
            border-radius: 8px;
        }
        .modal-copy-btn {
            margin-top: 20px;
            padding: 10px 25px;
            background-color: #2ecc71;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        .close-btn {
            position: absolute;
            top: -40px;
            right: -20px;
            color: white;
            font-size: 40px;
            cursor: pointer;
            transition: color 0.2s;
        }
        .close-btn:hover {
            color: #ddd;
        }
        /* 复制成功提示 */
        .toast {
            position: fixed;
            bottom: 30px;
            left: 50%;
            transform: translateX(-50%);
            padding: 12px 25px;
            background-color: rgba(0,0,0,0.8);
            color: white;
            border-radius: 4px;
            font-size: 14px;
            opacity: 0;
            transition: opacity 0.3s;
            z-index: 999;
        }
        .toast.show {
            opacity: 1;
        }
    </style>
</head>
<body>
    <h1 class="title">我的图床（点击图片预览，按钮复制链接）</h1>
    <div class="image-grid">
        <!-- 👇 替换为你的图片路径和名称（Gitee Pages路径格式：https://用户名.gitee.io/仓库名/图片路径） -->
        <div class="image-item">
            <img src="https://gaor_0.gitee.io/images/IMG_0539.HEIC" alt="旅行照片1" 
                 onclick="openModal('https://gaor_0.gitee.io/images/IMG_0539.HEIC', 'photo1.jpg')">
            <div class="image-info">
                <div class="image-name">photo1.jpg（旅行）</div>
                <button class="copy-btn" 
                        onclick="copyUrl('https://gaor_0.gitee.io/images/IMG_0539.HEIC')">
                    复制图片链接
                </button>
            </div>
        </div>
        <div class="image-item">
            <img src="https://gaor_0.gitee.io/images/IMG_0539.HEICg" alt="个人头像" 
                 onclick="openModal('https://gaor_0.gitee.io/images/IMG_0539.HEIC', 'avatar.png')">
            <div class="image-info">
                <div class="image-name">avatar.png（头像）</div>
                <button class="copy-btn" 
                        onclick="copyUrl('https://gaor_0.gitee.io/images/IMG_0539.HEIC')">
                    复制图片链接
                </button>
            </div>
        </div>
        <!-- 可继续添加图片项 -->
    </div>

    <!-- 预览弹窗 -->
    <div class="modal" onclick="closeModal()">
        <div class="modal-content">
            <span class="close-btn">&times;</span>
            <img id="modal-img" src="" alt="预览图">
            <button class="modal-copy-btn" id="modal-copy-btn">复制预览图链接</button>
        </div>
    </div>

    <!-- 复制成功提示 -->
    <div class="toast" id="toast">复制成功！</div>

    <script>
        const modal = document.querySelector('.modal');
        const modalImg = document.getElementById('modal-img');
        const modalCopyBtn = document.getElementById('modal-copy-btn');
        const toast = document.getElementById('toast');
        let currentImgUrl = ''; // 存储当前图片的URL

        // 打开预览弹窗
        function openModal(imgUrl, imgName) {
            modal.style.display = 'flex';
            modalImg.src = imgUrl;
            currentImgUrl = imgUrl; // 记录当前图片URL
            modalCopyBtn.onclick = () => copyUrl(imgUrl); // 绑定弹窗复制按钮事件
        }

        // 关闭预览弹窗
        function closeModal() {
            modal.style.display = 'none';
        }

        // 复制图片URL到剪贴板
        function copyUrl(url) {
            navigator.clipboard.writeText(url).then(() => {
                // 显示复制成功提示
                toast.classList.add('show');
                setTimeout(() => toast.classList.remove('show'), 2000);

                // 按钮状态变化（短暂显示“已复制”）
                const btn = event.currentTarget;
                if (btn) {
                    const originalText = btn.innerText;
                    btn.innerText = '已复制！';
                    btn.classList.add('copied');
                    setTimeout(() => {
                        btn.innerText = originalText;
                        btn.classList.remove('copied');
                    }, 1500);
                }
            }).catch(err => {
                alert('复制失败，请手动复制：' + url);
                console.error('复制错误：', err);
            });
        }

        // 点击关闭按钮关闭弹窗
        document.querySelector('.close-btn').onclick = closeModal;
        // 按ESC键关闭弹窗
        document.addEventListener('keydown', (e) => {
            if (e.key === 'Escape' && modal.style.display === 'flex') {
                closeModal();
            }
        });
    </script>
</body>
</html>